/**
 *
 */
package com.nest.WorkNest.act;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.nest.WorkNest.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 */
public class UpdateUser extends BaseActivity {

    @Bind(R.id.edtTxt_inputname)
    EditText edtTxtInputname;
    @Bind(R.id.edtTxt_intro)
    EditText edtTxtIntro;
    private Intent mIntent;
    private String type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_update_user);
        ButterKnife.bind(this);
        initHeadView();
        mIntent = getIntent();
        if (mIntent.getExtras() != null) {
            type = mIntent.getExtras().getString("type");
            if ("intro".equals(type)) {
                edtTxtIntro.setVisibility(View.VISIBLE);
                inputIntro();
            } else {
                edtTxtInputname.setVisibility(View.VISIBLE);
                inputName(type);
            }
        }
    }

    private void initHeadView() {
        initBar();
        actionbar_side_name.setVisibility(View.VISIBLE);
        actionbar_side_name.setText("请填写");
        ll_iv_actionbar_side_left.setVisibility(View.VISIBLE);
        ll_tv_actionbar_side_left.setVisibility(View.VISIBLE);
        tv_actionbar_side_left.setText("保存");
        back();
    }

    public void inputName(final String type) {
        ll_actionbar_side_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent();
                String name = edtTxtInputname.getText().toString();
                if (type.equals("nickname")) {
                    intent.putExtra("nickname", name);
                } else if (type.equals("myname")) {
                    intent.putExtra("myname", name);
                } else if (type.equals("email")) {
                    intent.putExtra("email", name);
                } else if (type.equals("payway")) {
                    intent.putExtra("payway", name);
                } else if (type.equals("idnum")) {
                    intent.putExtra("idnum", name);
                } else if (type.equals("companyname")) {
                    intent.putExtra("companyname", name);
                } else if (type.equals("storelink")) {
                    intent.putExtra("storelink", name);
                } else if (type.equals("phone")) {
                    intent.putExtra("phone", name);
                }
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        String text = "";
        if (type.equals("nickname")) {
            text = mIntent.getExtras().getString("nickname");
        } else if (type.equals("myname")) {
            text = mIntent.getExtras().getString("myname");
        } else if (type.equals("email")) {
            text = mIntent.getExtras().getString("email");
        } else if (type.equals("payway")) {
            text = mIntent.getExtras().getString("payway");
        } else if (type.equals("idnum")) {
            text = mIntent.getExtras().getString("idnum");
        } else if (type.equals("companyname")) {
            text = mIntent.getExtras().getString("companyname");
        } else if (type.equals("storelink")) {
            text = mIntent.getExtras().getString("storelink");
        } else if (type.equals("phone")) {
            text = mIntent.getExtras().getString("phone");
        }
        edtTxtInputname.setText(text);
    }

    public void inputIntro() {
        ll_actionbar_side_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent();
                String input = edtTxtIntro.getText().toString();
                intent.putExtra("intro", input);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        String text = mIntent.getExtras().getString("intro");
        edtTxtIntro.setText(text);
    }
}
